#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Taotie Ren


def Login(username,password):
    """
    用于用户登陆
    :param username: 用户输入的用户名
    :param password: 用户输入的密码
    :return:
            True：表示登陆成功
            False：登陆失败

    """
    f = open("db",'r')
    for line in f:
        line_list = line.strip().split("|")
        if line_list[0] == username and line_list[1] == password:
            return True
    return False


def Register(username,password):
    """
    用于用户注册
    :param username:用户名
    :param password:密码
    :return:默认None
    """
    f = open("db", 'a')
    temp = "\n" + username + "|" + password
    f.write(temp)
    f.close()


def main():
    t = input("1:登陆；2:注册")
    if t == "1":
        user = input("请输入用户名：")
        pwd = input("请输入密码：")
        r = Login(user,pwd)
        if r:
            print("登陆成功")
        else:
            print("登录失败")
    elif t == "2":
        print("注册")
        user = input("请输入用户名：")
        pwd = input("请输入密码：")
        Register(user,pwd)

main()



